package model;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;

/**
 * <p>
 * Title: Edge</p>
 * <p>
 * Description: CS 343 Project. The Edge data model.</p>
 *
 *
 * @date 11/18/2013
 *
 * @author Dylan Ahmann
 * @author Gregg Roemhildt - Class Programming and Javadocs
 * @author Sam Brockmann - Javadocs
 * @author Emily Hancock - Javadocs
 * @author Shirin Asadi
 *
 *
 * @param <T> type of data stored in Vertex
 */
//@Entity
public class Edge<T extends Serializable> implements Serializable {

    protected Vertex<T> a;
    protected Vertex<T> b;
    private double weight;
//    @Id
//    private Long id;

    /**
     * Default constructor Implicitly sets values to null
     *
     */
    public Edge() {
        a = null;
        b = null;
        weight = 1.0;
    }

    /**
     * constructor Initializes the a and b, which are the "To" and "From" values
     * of this edge, and the weight.
     *
     * @param a Vertex a
     * @param b Vertex b
     *
     */
    public Edge(Vertex<T> a, Vertex<T> b) {
        a.addEdge(this);
        b.addEdge(this);
        this.a = a;
        this.b = b;
        weight = 1; //default weight of 1
    }

    /**
     * alternate constructor Initializes the a and b, which are the "To" and
     * "From" values, and the weight.
     *
     * @param a Vertex a
     * @param b Vertex b
     * @param w Weight
     *
     */
    public Edge(Vertex<T> a, Vertex<T> b, double w) {
        a.addEdge(this);
        b.addEdge(this);
        this.a = a;
        this.b = b;
        weight = w;
    }

    /**
     * Copy Constructor Performs a deep copy.
     *
     * @param e edge to copy
     *
     */
    public Edge(Edge<T> e) {
        this.a = new Vertex<>(e.a);
        this.b = new Vertex<>(e.b);
        this.weight = e.weight;
    }

    /**
     * getA - getter for a, the first Vertex
     *
     * @return a
     */
    public Vertex getA() {
        return a;
    }

    /**
     * getB - getter for b, the second Vertex
     *
     * @return b
     */
    public Vertex getB() {
        return b;
    }

    /**
     * getWeight - getter for this edges weight
     *
     * @return weight
     */
    public double getWeight() {
        return weight;
    }

    /**
     * setWeight - sets the weight of the edge
     *
     * @param w weight variable
     */
    public void setWeight(double w) {
        weight = w;
    }

    /**
     * toString - toString method for Edge class
     *
     * @return String
     */
    @Override
    public String toString() {
        return "Edge from " + a + " to " + b + "\n";
    }

    /**
     * getNeighbor
     *
     * @param v Vertex
     * @return other Vertex
     */
    public Vertex<T> getNeighbor(Vertex v) {
        if (v.equals(this.a)) {
            return b;
        } else if (v.equals(b)) {
            return a;
        }
        System.out.println("error in edge getNeighbor");
        return null;
    }

//    /**
//     *
//     * @return this edges id
//     */
//    public Long getId() {
//        return id;
//    }
//
//    /**
//     *
//     * @param id id to set
//     */
//    public void setId(Long id) {
//        this.id = id;
//    }
}
